<?php
/**
 * 问答控制层
 * 
 * @copyright 	Copyright (c) 2011 thinkapk.com All rights reserved.
 * @package 	ThinkAPK_Action
 * @link 		http://www.thinkapk.com/
 * @author 		richie <richbossman@163.com>
 * @version 	$Id: QuestionInfoAction.class.php 7380 2011-06-04 9:26:35Z richie $
 * 
 */
class QuestionAction extends ThinkAPK_Action_Mall {
	
	/*
	 * ajax取商品问答
	*/
	public function getGoodsQuestion(){
		$goods_id=is_numeric($_GET['goods_id'])?$_GET['goods_id']:0;
		if(!$goods_id) $this->error('商品ID不正确');
		$cat_id=is_numeric($_GET['cat_id'])?$_GET['cat_id']:0;
		$keyword=trim($_GET['keyword']);
		
		$question_cat=$this->getCate($goods_id);
		if($question_cat) $this->assign('question_cat',$question_cat);
		unset($QCM,$public_cat);
		$wenda=D('QuestionInfo')->getQuestionList($question_cat,$cat_id,$keyword);
		if($wenda) $this->assign('wenda_list',$wenda);
		$total=$wenda['total']?$wenda['total']:0;
		unset($wenda,$keyword,$cat_id,$goods_id,$question_cat);

		if(isset($_GET['click_tag'])){
			$html=$this->fetch('/common:goods_question');
		}else{
			$html=$this->fetch('/common:goods_question_list');
		}
		$this->success($html,array('total'=>$total));
	}
	
	/*
	 *AJAX取问答总数
	*/
	public function getWendaTotal(){
		$goods_id=is_numeric($_GET['goods_id'])?$_GET['goods_id']:0;
		if(!$goods_id) $this->error('0');
		$cate=$this->getCate($goods_id);
		$total=D('QuestionInfo')->getCountQueston($cate);
		unset($cate);
		if($total)	$this->success($total);
		else $this->error('没有问答');
	}
	
	protected function getCate($goods_id){
		//当前商品的问答分类
		$QCM=new QuestionCatModel();
		$question_cat=$QCM->getQuestionCat($goods_id);
		$public_cat=$QCM->getPublicQuestionCat($goods_id);
		if($question_cat && $public_cat) $question_cat=array_merge($question_cat,$public_cat);
		elseif($public_cat) $question_cat=$public_cat;
		return $question_cat;
	}
}
?>